package com.vspush.manage;

import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;

import java.net.InetSocketAddress;

import com.vspush.cache.Cache;
import com.vspush.udp.model.User;
import com.vspush.util.StringUtils;

public class UserManage {
	
	public static User getUserByUserName(String username){
		return (User) Cache.get(username);
	}
	
	public static void login(String userName,String password,InetSocketAddress isa,Channel ch){
		try {
			ch.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(StringUtils.enlogin(userName,password), CharsetUtil.UTF_8),isa)).sync();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public static void login(String userName,String password,InetSocketAddress isa,ChannelHandlerContext ch){
		try {
			ch.writeAndFlush(new DatagramPacket( Unpooled.copiedBuffer(StringUtils.enlogin(userName,password), CharsetUtil.UTF_8),isa)).sync();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
